<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>添加项目</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../css/index.css">
		<link rel="stylesheet" href="../../layui/css/layui.css" />
</head>
<body>

  <div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
    
     <div class="layui-form-item">
      <label class="layui-form-label">赛事性质</label>
      <div class="layui-input-inline">
        <select id="quality" name="quality" lay-filter="quality" lay-verify="required">
          <option value="">请选择赛事性质</option>
          <option value="1">田赛</option>
          <option value="2">径赛</option>
        </select>
      </div>
    </div>
    <!-- 隐藏控件 -->
    <input type="hidden" id="signupid" name="signupid" class="layui-input">
    <div class="layui-form-item" id="show1" style="display:none">
      <label class="layui-form-label">成绩</label>
      <div class="layui-input-inline">
        <input type="text" id="result1" name="result1"  placeholder="只能输入数字和小数点" class="layui-input">
      </div>
      <div class="layui-form-mid layui-word-aux" style="color:red;">例：1.2</div>
    </div>
    
    <div class="layui-form-item" id="show2" style="display:none">
      <label class="layui-form-label">成绩</label>
      <div class="layui-input-inline">
        <input type="text" id="result2" name="result2"  placeholder="必须输入时分秒毫秒"  class="layui-input">
      </div>
      <div class="layui-form-mid layui-word-aux" style="color:red;">例：01:59:59:999</div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">当前名次</label>
      <div class="layui-input-inline">
         <select name="Ranking" id="Ranking" lay-filter="Ranking">
                <option value="">请选择名次</option>
              </select>
      </div>
    </div>
    <div class="layui-form-item layui-hide">
      <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="确认添加">
      <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="确认编辑">
    </div>
  </div>

 <script type="text/javascript" src="../../layui/layui.all.js" charset="utf-8"></script> 

<script type="text/javascript">
 layui.use(['table','jquery','form','layer'], function(){
  var table = layui.table;
  var $ = layui.jquery;
  var form=layui.form;
  var layer = layui.layer;
  
       
 		var Groupid = sessionStorage.getItem('Groupid');
  		
  		
  		if(Groupid == null || Groupid == ""){
  			 layer.msg("请重新选择录入数据");
  			 return;
  		}else{
  			//取得当前组总共有多少名，赋值给，传入一个当前分组的编号
			$.ajax({
				type: 'get',
				url: '../../dropdown/getgroupnumbyGroupid?groupid=' + Groupid,
				datatype: 'json',
				success: function(roledata) {
				
					//alert(roledata.data);
					if(roledata.code == 0) {
						var str = "";
						for(var i = 0; i < roledata.count; i++) {
							str += '<option value=' + roledata.data[i].id + '>' +'第'+ roledata.data[i].id + '名' + '</option>';
						}
				   		 $("#Ranking").append(str);
						form.render();
					} else {
							layer.msg("名次获取失败");
					}
				},
				error: function() {
					layer.msg("名次获取失败");
				}
			});
  
  		}
  		
    //监听提交,添加事件
    form.on('submit(layuiadmin-app-form-submit)', function(data){
      var field = data.field; //获取提交的字段
      var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引  
 			
 			if(data.field.result2 != null && data.field.result2 != ""){
 				if(!new RegExp("^([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]):([0-9][0-9][0-9])$").test(data.field.result2)){
			     layer.msg("成绩格式错误");
			      return;
				}
 			}
 			
			if(data.field.result1 != null && data.field.result1 != ""){//只能输入一个小数点的正则表达式
				if(!new RegExp("^[-]?[0-9]+\.?[0-9]+?$/.test(str1)||/^[0-9]+$").test(data.field.result1)){
			     layer.msg("成绩格式错误");
			      return;
				}
			}
			
			var Groupid = sessionStorage.getItem('Groupid');
			
			var param = "?signupid=" + field.signupid + "&result1=" + field.result1 + "&result2="
						+ field.result2 + "&Ranking=" + field.Ranking + "&groupid=" + Groupid;
			//alert(param)
			$.ajax({
				url:"../../scoremana/addachieve" + param,
				type:"POST",
				data:null,
				dataType : "json",
				xhrFields :{
					withCredentials: true
				},
				contentType:'application/json;charset=UTF-8',
				success:function(e){
					//alert(e.msg)
					if(e.code == 0){
						layer.msg(e.msg,{icon:6}); 
					}else{
						layer.msg(e.msg,{icon:5});
						return;
					}
					setTimeout(function(){
						parent.layer.close(index); //再执行关闭 
      					parent.layui.table.reload('achiinfo'); //重载表格
					},1*1000)
					
				},
				error:function(e){
					layer.msg(e.msg,{icon:5});
					
				}
			})
      	return false;
    });
    
   		 //赛程分组的下拉联动
		form.on('select(quality)', function(data){
			//alert(data.value == 1)
			if(data.value == 1){
				$("#show1").show();
				$("#show2").hide();
			}else if(data.value == 2){
				$("#show2").show();
				$("#show1").hide();
			}else{
				$("#show1").hide();
				$("#show2").hide();
			}
		 })
  
  		
});
</script>
</body>
</html>